/*
** xfct.c for  in /home/jousse_f//workspace/SysUnix/script
** 
** Made by florian jousseau
** Login   <jousse_f@epitech.net>
** 
** Started on  Wed Feb 22 12:18:03 2012 florian jousseau
** Last update Wed Feb 22 12:34:36 2012 florian jousseau
*/

#include "my_script.h"

ssize_t		xwrite(int fd, const void *buffer, size_t size)
{
  ssize_t ret;

  ret = write(fd, buffer, size);
  if (ret == -1)
    {
      printf("Error from write\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int	xselect(int nfds, fd_set *readfds, fd_set *writefds,
		fd_set *errorfds, struct timeval *timeout)
{
  int ret;

  ret = select(nfds, readfds, writefds, errorfds, timeout);
  if (ret == -1)
    {
      printf("Error from select\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int	xtcgetattr(int fd, struct termios *termios_p)
{
  int ret;

  ret = tcgetattr(fd, termios_p);
  if (ret == -1)
    {
      printf("Error from tcgetattr\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int xtcsetattr(int fd, int optional_actions, const struct termios *termios_p)
{
  int ret;

  ret = tcsetattr(fd, optional_actions, termios_p);
  if (ret == -1)
    {
      printf("Error from tcsetattr\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int	xdup2(int oldfd, int newfd)
{
  int	ret;

  ret = dup2(oldfd, newfd);
  if (ret == -1)
    {
      printf("Error from dup2\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}
